package com.wangp.mywrite.coding;

import java.util.Arrays;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @description: 2341. 数组能形成多少数对
 * @author tooStronger
 * @date 2023/2/16
 */
public class NumberOfPairs {

    public int[] numberOfPairs(int[] nums) {
        if (nums.length <= 1) {
            return new int[]{0, nums.length};
        }
        int[] flag = new int[nums.length];

        int pairs = 0;
        for (int i = 0; i < nums.length; i++) {
            if(flag[i] == 1){
                continue;
            }
            for (int j = i + 1; j < nums.length; j++) {
                if (flag[j] == 1) {
                    continue;
                }
                if (nums[i] == nums[j]) {
                    pairs++;
                    flag[i] = 1;
                    flag[j] = 1;
                    break;
                }
            }
        }
        int count = 0;
        for (int j : flag) {
            if (j != 1) {
                count++;
            }
        }
        return new int[]{pairs,count};
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new NumberOfPairs().numberOfPairs(new int[]{1, 3, 2, 1, 3, 2, 2})));
    }
}
